import jsonp from '@/assets/js/jsonp'
import axios from 'axios'
import {
  commonParams,
  options
} from './config'

export function getHotKey() {
  const url = 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg'

  const data = Object.assign({}, commonParams, {
    uin: 0,
    needNewCode: 1,
    platform: 'h5'
  })

  return jsonp(url, data, options)
}

export function search(query, page, zhida, perpage) {
  const url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'

  const data = Object.assign({}, commonParams, {
    w: query,
    p: page,
    perpage,
    n: perpage,
    catZhida: zhida ? 1 : 0,
    zhidaqu: 1,
    t: 0,
    flag: 1,
    ie: 'utf-8',
    sem: 1,
    aggr: 0,
    remoteplace: 'txt.mqq.all',
    uin: 0,
    needNewCode: 1,
    platform: 'h5'
  })

  return jsonp(url, data, options)
}
export function search2(query, page, zhida, pageSize) {
  const url = '/search'
  const data = Object.assign({
    key: query,
    pageNo: page,
    zhidaqu: zhida ? 1 : 0,
    catZhida: 1,
    t: 0,
    flag: 1,
    ie: 'utf-8',
    sem: 1,
    aggr: 0,
    pageSize,
    perpage: 20,
    n: 20,
    p: 1,
    _: 1605944619550,
    g_tk: 5381,
    uin: '',
    format: 'json',
    inCharset: 'utf - 8',
    outCharset: 'utf - 8',
    notice: 0,
    platform: 'h5',
    needNewCode: 1,
    g_tk_new_20200303: 1872031642,
  })
  return axios.request({
    url,
    method: 'get',
    params: data
  })
}